package com.jiepos.mpos.biz.http.controller;

import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.jiepos.mpos.biz.http.service.HttpCommonService;
import com.jiepos.mpos.biz.http.service.HttpCustomService;
import com.jiepos.mpos.common.entity.App_Custom_InfEntity;
import com.jiepos.mpos.common.entity.GpsEntity;
import com.jiepos.mpos.inter.message.service.RandService;

/**
 * 
 * <p>标题: —— app客户端一些不涉及到业务的请求数据控制器</p>
 * <p>模块: app通信模块</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @author 娄伟峰
 * @version 1.0
 * @since 2017年9月15日 下午1:48:51
 * @history（历次修订内容、修订人、修订时间等）
 */
@Controller
@RequestMapping("httpcommon")
public class HttpCommonController {
	@Autowired
	private HttpCommonService httpCommonService;
	@Autowired
	private RandService randService;
	@Autowired
	private HttpCustomService httpCustomService;
	/**
	 * 初始化app
	 * @param request
	 * @param response
	 * @param serial_number
	 * @param random_number
	 * @param version
	 * @param gpsEntity
	 * @return
	 */
	@RequestMapping("/initSystem.do")
	public @ResponseBody Map initSystem(HttpServletRequest request, HttpServletResponse response,
			String serial_number,String random_number,String version,String sign,GpsEntity gpsEntity){
		return httpCommonService.queryInitParam(request,sign,gpsEntity);
	}
	
	/**
	 * 获取验证码
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping("/getRand.do")
	public @ResponseBody Map getRand(HttpServletRequest request, HttpServletResponse response,
			String serial_number,String sign,String random_number,String version,
			String phone,String custom_uuid,String custom_name,String certificate_no,String type,GpsEntity gpsEntity){
		return httpCommonService.getHttpRand(request,serial_number,sign,random_number,version,phone,custom_uuid,custom_name,certificate_no,type,gpsEntity);
 
	}
	
	/**
	 * 获取地区
	 * @param request
	 * @param response
	 * @param random_number
	 * @param sign
	 * @param login_id
	 * @param custom_no
	 * @param gpsEntity
	 * @return
	 */
	@RequestMapping("/getArea.do")
	public @ResponseBody Map getArea(HttpServletRequest request, HttpServletResponse response,
			String random_number,String sign,String login_id,String custom_no,GpsEntity gpsEntity){
		return httpCommonService.getArea(request,sign,random_number,login_id,custom_no,gpsEntity);
	}
	
	/**
	 * 获取总行信息
	 * @param request
	 * @param response
	 * @param random_number
	 * @param sign
	 * @param login_id
	 * @param custom_no
	 * @param gpsEntity
	 * @return
	 */
	@RequestMapping("/getSuperBank.do")
	public @ResponseBody Map getSuperBank(HttpServletRequest request, HttpServletResponse response,
			String random_number,String sign,String login_id,String custom_no,GpsEntity gpsEntity){
		return httpCommonService.getSuperBank(request,sign,random_number,login_id,custom_no,gpsEntity);
	}
	
	/**
	 * 获取联行号
	 * @param request
	 * @param response
	 * @param random_number
	 * @param sign
	 * @param login_id
	 * @param custom_no
	 * @param area_cd
	 * @param super_bank_no
	 * @param gpsEntity
	 * @return
	 */
	@RequestMapping("/getCnaps.do")
	public @ResponseBody Map getCnaps(HttpServletRequest request, HttpServletResponse response,
			String random_number,String sign,String login_id,String custom_no,String area_cd,String super_bank_no,GpsEntity gpsEntity){
		return httpCommonService.getCnaps(request,sign,random_number,login_id,custom_no,area_cd,super_bank_no,gpsEntity);
	}

	/**
	 * 查询通知公告列表
	 * @return
	 */
	@RequestMapping("/getNoticeList.do")
	public @ResponseBody Map getNoticeList(HttpServletRequest request, HttpServletResponse response,String random_number,
										   String login_id,String custom_no,String send_type, String begin_tm,String end_tm,
										   String curr_page,String rows_perpage,String sign,GpsEntity gpsEntity){
		return httpCommonService.getNoticeList(request,random_number,login_id,custom_no,send_type,begin_tm,end_tm,
				curr_page,rows_perpage,sign,gpsEntity);
	}

	/**
	 * 查询通知公告详情
	 * @return
	 */
	@RequestMapping("/getNoticeDetail.do")
	public @ResponseBody Map getNoticeDetail(HttpServletRequest request, HttpServletResponse response,String random_number,
											 String login_id,String custom_no,String message_uuid,String is_index,String read_st,String sign,GpsEntity gpsEntity){

		return httpCommonService.getNoticeDetail(request,random_number,login_id,custom_no,message_uuid,is_index,read_st,sign,gpsEntity);
	}

	/**
	 * 获取下一条通知公告
	 * @return
	 */
	@RequestMapping("/getNextNoticeInfo.do")
	public @ResponseBody Map getNextNoticeInfo(HttpServletRequest request, HttpServletResponse response, String login_id, String random_number,
								 String custom_no, String sign, GpsEntity gpsEntity){
		return httpCommonService.getNextNoticeInfo(request,login_id,random_number,custom_no,sign,gpsEntity);
	}

	/**
	 * 通知公告全部设置已读
	 * @return
	 */
	@RequestMapping("/setNoticeInfoRead.do")
	public @ResponseBody Map setNoticeInfoRead(HttpServletRequest request, HttpServletResponse response, String login_id, String random_number, String custom_no,String message_type,String sign, GpsEntity gpsEntity){
		return httpCommonService.setNoticeInfoRead(request,login_id,random_number,custom_no,message_type,sign,gpsEntity);
	}

	/**
	 * 检测更新
	 */
	@RequestMapping("/checkVersion.do")
	public @ResponseBody Map checkVersion(HttpServletRequest request, HttpServletResponse response,
									String login_id, String random_number,String custom_no,String sign,GpsEntity gpsEntity){
		return httpCommonService.checkVersion(request,login_id,random_number,custom_no,sign,gpsEntity);
	}

	/**
	 * 客户端帮助信息列表
	 */
	@RequestMapping("/getHelpList.do")
	public @ResponseBody Map getHelpList(HttpServletRequest request, HttpServletResponse response,
										  String login_id, String random_number,String custom_no,String sign,GpsEntity gpsEntity){
		return httpCommonService.getHelpList(request,login_id,random_number,custom_no,sign,gpsEntity);
	}

	/**
	 * 客户端帮助信息详细信息
	 */
	@RequestMapping("/getHelpDetail.do")
	public @ResponseBody Map getHelpDetail(HttpServletRequest request, HttpServletResponse response,
										 String login_id, String random_number,String custom_no,String help_uuid,String sign,GpsEntity gpsEntity){
		return httpCommonService.getHelpDetail(request,login_id,random_number,custom_no,help_uuid,sign,gpsEntity);
	}

	/**
	 * 获取某个类型的客户端帮助信息详细信息
	 */
	@RequestMapping("/getHelpDetailByTp.do")
	public @ResponseBody Map getHelpDetailByTp(HttpServletRequest request, HttpServletResponse response,
										 String login_id, String random_number,String custom_no,String help_tp,String sign,GpsEntity gpsEntity){
		return httpCommonService.getHelpDetailByTp(request,login_id,random_number,custom_no,help_tp,sign,gpsEntity);
	}

	/**
	 * 查询我的推广二维码
	 */
	@RequestMapping("/getMyShareQr.do")
	public @ResponseBody Map getMyShareQr(HttpServletRequest request, HttpServletResponse response,
										   String login_id, String random_number,String custom_no,String sign,GpsEntity gpsEntity){
		return httpCommonService.getMyShareQr(request,login_id,random_number,custom_no,sign,gpsEntity);
	}


	/**
	 * 单张上传图片
	 */
	@RequestMapping("/uploadPic.do")
	public @ResponseBody Map uploadPic(HttpServletRequest request, HttpServletResponse response,
									   String login_id, String random_number, String custom_no, String affix_tp, String store_tp,
									   @RequestParam(value = "imgContent",required = false) MultipartFile imgContent, String sign, GpsEntity gpsEntity){
		return httpCommonService.uploadPic(request,response,login_id,random_number,custom_no,affix_tp,store_tp,imgContent,sign,gpsEntity);
	}
	
	@RequestMapping("/logout.do")
	@ResponseBody
	public Map logout(HttpServletRequest request, HttpServletResponse response,
			String login_id,String random_number,String custom_no,String sign,GpsEntity gpsEntity){
		return httpCommonService.logout(request,login_id,random_number,custom_no,sign,gpsEntity);
	}

	/**
	 * 我的二维码页面
	 * @param request
	 * @param response
	 * @param sup_custom_uuid
	 * @param sign
	 * @param gpsEntity
	 * @return
	 */
	@RequestMapping("/httpReg.do")
	public ModelAndView httpReg(HttpServletRequest request, HttpServletResponse response,
								String sup_custom_uuid,String sign, GpsEntity gpsEntity){
		response.setHeader("Pragma","no-cache");
		response.setHeader("cache-control","no-cache");
		response.setDateHeader("Expires", 0);
		ModelAndView model = new ModelAndView("/module/http/share");
		String supLoginById = httpCustomService.getSupLoginById(sup_custom_uuid);
		model.addObject("sup_custom_uuid",sup_custom_uuid);
		model.addObject("sup_login_id",supLoginById);
		return model;
	}
	/**
	 * 获取验证码
	 * @return
	 */
	@RequestMapping(value = "/getShareRand.do")
	public @ResponseBody
	Map getCustomInfo(HttpServletRequest request, HttpServletResponse response,
					  String phone,String type,String sup_custom_uuid,Map dataMap, String sign, GpsEntity gpsEntity){
		return randService.getRand(phone,type,null,sup_custom_uuid,null);
	}

	/**
	 * 分享注册
	 * @return
	 */
	@RequestMapping(value = "/share.do")
	public @ResponseBody
	Map initSystem(HttpServletRequest request, HttpServletResponse response,
				   String login_id, String pass_word, String rand, String sign, GpsEntity gpsEntity, App_Custom_InfEntity appCustomInfEntity, String pay_pass_word,String sup_custom_uuid) throws Exception {
		Map dataMap = httpCustomService.queryShareCustomParam(request, sign, gpsEntity, login_id, pass_word, rand, appCustomInfEntity, pay_pass_word,sup_custom_uuid);
		return dataMap;
	}
	/**
	 * 用户手机号校验
	 * @return
	 */
	@RequestMapping(value = "/getLoginId.do")
	public @ResponseBody
	boolean getLoginId(HttpServletRequest request, HttpServletResponse response,
				   String login_id, String sign, GpsEntity gpsEntity) throws Exception {
		Boolean strResult =  httpCustomService.getLoginId(request,response,login_id,sign,gpsEntity);
		return strResult;
	}

	/**
	 * 用户验证码校验
	 * @return
	 */
	@RequestMapping(value = "/ifExistRand.do")
	public @ResponseBody
	void ifExistRand(HttpServletRequest request, HttpServletResponse response,
					String login_id, String service_type) throws Exception {
		boolean ifExistRand =  httpCustomService.ifExistRand(request,response,login_id,service_type);
		String str = String.valueOf(ifExistRand);
		//输出
		PrintWriter out = response.getWriter();
		out.write(str.toString());
	}
	/**
	 * 用户验证码校验(是否正确)
	 * @return
	 */
	@RequestMapping(value = "/getCheckRand.do")
	public @ResponseBody
	boolean getCheckRand(HttpServletRequest request, HttpServletResponse response,
					 String login_id, String service_type,String rand) throws Exception {
		boolean getCheckRand =  httpCustomService.getCheckRand(request,response,login_id,service_type,rand);
		return getCheckRand;
	}

	/**
	 * 下载地址
	 * @param request
	 * @param response
	 * @param sup_custom_uuid
	 * @return
	 */
	@RequestMapping(value = "/httpDownload.do")
	public ModelAndView httpDownload(HttpServletRequest request, HttpServletResponse response,
								String sup_custom_uuid){
		ModelAndView model = new ModelAndView("/module/http/jqianbao");
		String apkUrl = httpCustomService.httpDownload(sup_custom_uuid);
		model.addObject("apkUrl",apkUrl);
		return model;
	}
	/**
	 * 根据分享类型获取分享信息列表
	 */
	@RequestMapping("/getShareByTp.do")
	public @ResponseBody Map getShareByTp(HttpServletRequest request, HttpServletResponse response,
										  String login_id, String random_number,String custom_no,String share_tp,String sign,String curr_page,String rows_perpage ,GpsEntity gpsEntity){
		return httpCommonService.getShareByTp(request,login_id,random_number,custom_no,share_tp,curr_page,rows_perpage,sign,gpsEntity);
	}


	/**
	 * 根据分享内容主键获取分享信息详情
	 */
	@RequestMapping("/getShareDetailById.do")
	public @ResponseBody Map getShareDetailById(HttpServletRequest request, HttpServletResponse response,
										  String login_id, String random_number,String custom_no,String share_uuid,String sign,GpsEntity gpsEntity){
		return httpCommonService.getShareDetailById(request,login_id,random_number,custom_no,share_uuid,sign,gpsEntity);
	}

    /**
     * 上传错误报告
     */
    @RequestMapping("/uploadErrorReport.do")
    public @ResponseBody Map uploadErrorReport(HttpServletRequest request, HttpServletResponse response,
											   GpsEntity gpsEntity,String login_id,
                                       @RequestParam(value = "err_report_file",required = false) MultipartFile err_report_file){
        return httpCommonService.uploadErrorReport(request,response,gpsEntity,err_report_file,login_id);
    }

}
